import codecs
import os
import re
import sys
import threading
import urllib.request
import bs4
from queue import Queue
from threading import Thread

header = {
    "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/121.0.0.0 Safari/537.36",
}
# import htmlMannger
# 0.拼接网址
sys.stdout = codecs.getwriter("utf-8")(
    sys.stdout.detach())  ##神呀，终于解决UnicodeEncodeError: 'ascii' codec can't encode characters in position 0-1: ordinal not in range(128)


# 0.请求页面
def get_html(url):
    res_html = urllib.request.urlopen(url=urllib.request.Request(url=url), timeout=10).read().decode('utf-8')
    res_soup = bs4.BeautifulSoup(res_html, 'html.parser')
    return res_soup


def getUrl(url):
    targeturl = "https://www.66s6.net" + url
    return targeturl


# 1.请求html页面
def getHtml(url):
    playurl = getUrl(url)
    # print(playurl)
    res_soup = get_html(playurl)
    return res_soup


# 2.处理html页面
def getPlayUrl(playurl):
    ressoup = getHtml(playurl)
    # print(ressoup)
    playUrl = ressoup.find('div', class_='video').find('iframe')['src']
    return playUrl


if __name__ == '__main__':
    # url="/e/DownSys/play/?classid=2&id=22776&pathid1=0&bf=0"
    url = sys.argv[1]
    # print(url)
    print(getPlayUrl(url))
